# CMake 最低版本要求
cmake_minimum_required(VERSION 3.15) # 提高版本以更好地支持 vcpkg

# 项目名称和语言
project(TetrisLeaderboardAPI LANGUAGES CXX)

# 设置 C++ 标准为 C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# --- 使用 vcpkg ---
# 设置 vcpkg triplet (根据你的环境修改)
set(VCPKG_TARGET_TRIPLET "x64-mingw-dynamic" CACHE STRING "Vcpkg target triplet")
# 设置 vcpkg 工具链文件路径 (根据你的环境修改)
# set(CMAKE_TOOLCHAIN_FILE "D:/Dev/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE PATH "Vcpkg toolchain file")
# 如果 CMAKE_TOOLCHAIN_FILE 是通过命令行传递的，这里就不需要设置了

# --- 查找 vcpkg 提供的包 ---
find_package(asio CONFIG REQUIRED)
find_package(Crow CONFIG REQUIRED) # vcpkg 中的包名通常是 Crow
find_package(nlohmann_json CONFIG REQUIRED)

# --- 查找 Windows 特定的网络库 (如果 MinGW 需要) ---
# vcpkg 通常会处理依赖，但为保险起见，可以保留 Winsock 查找
if(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") # 仅在 Windows MinGW 环境下查找
    set(TDM_GCC_LIB_PATH "D:/Dev/TDM-GCC-64/x86_64-w64-mingw32/lib") # <--- 修改为你的 TDM-GCC lib 路径
    message(STATUS "正在搜索 Winsock 库路径: ${TDM_GCC_LIB_PATH}")
    find_library(WS2_32_LIBRARY ws2_32 HINTS ${TDM_GCC_LIB_PATH} REQUIRED)
    find_library(WSOCK32_LIBRARY wsock32 HINTS ${TDM_GCC_LIB_PATH} REQUIRED)
    message(STATUS "找到 ws2_32 库: ${WS2_32_LIBRARY}")
    message(STATUS "找到 wsock32 库: ${WSOCK32_LIBRARY}")
    set(WINSOCK_LIBS ${WS2_32_LIBRARY} ${WSOCK32_LIBRARY})
else()
    set(WINSOCK_LIBS "") # 其他平台或编译器不需要显式链接
endif()

# --- 可执行文件 ---
add_executable(tetris_leaderboard_api main.cpp)

# --- 链接库 ---
target_link_libraries(tetris_leaderboard_api PRIVATE
    asio::asio          # vcpkg 提供的 Asio 目标
    Crow::Crow          # vcpkg 提供的 Crow 目标
    nlohmann_json::nlohmann_json # vcpkg 提供的 nlohmann_json 目标
    ${WINSOCK_LIBS}     # 链接 Winsock 库 (如果需要)
)

# --- 可选：改善构建输出 ---
set(CMAKE_VERBOSE_MAKEFILE ON)

# --- 输出信息 ---
message(STATUS "已配置 TetrisLeaderboardAPI 项目。")
message(STATUS "使用 vcpkg triplet: ${VCPKG_TARGET_TRIPLET}")
message(STATUS "源文件: ${CMAKE_SOURCE_DIR}/main.cpp")
